using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using DTO;
using System.Data;
namespace DAOLayer
{
    public class ChiTietMuonSachDAO:AbStractDao
    {
        public ChiTietMuonSachDAO()
        {
            this.connect();
        }
        
        public static DataTable getListChiTietMuonSach()
        {
            string query = "SELECT * FROM ChiTietMuonSach";
            ChiTietMuonSachDAO dgDao = new ChiTietMuonSachDAO();
            DataTable dt = dgDao.fillDataTable(query);
            dgDao.disconnect();           
            return dt;
        }
        public static ChiTietMuonDTO getChiTietMuonSach(int maChiTietMuonSach)
        {
            string strQuery = "select * from ChiTietMuonSach where MaChiTietMuonSach= " + maChiTietMuonSach;
            ChiTietMuonSachDAO dgDao = new ChiTietMuonSachDAO();
            IDataReader dr = dgDao.executeQuery(strQuery);
            ChiTietMuonDTO dgDto = new ChiTietMuonDTO();
            if (dr.Read())
            {
                dgDto.MaMuonSach = dr.GetInt32(0);
                dgDto.MaCuonSach = dr.GetInt32(1);
            }
            dgDao.disconnect();
            return dgDto;
        }
        public bool insert(ref ChiTietMuonDTO info)
        {
            string insertCommand = "INSERT INTO ChiTietMuonSach(MaMuonSach,MaCuonSach) VALUES(" +
                                        info.MaMuonSach + "," + info.MaCuonSach + ")";
                
            bool flag = executeNonQuery(insertCommand);     
            return flag;
        }
        public bool delete(ChiTietMuonDTO info)
        {
            string deleteCommand = "DELETE FROM ChiTietMuonSach WHERE MaMuonSach = " + info.MaMuonSach + " and MaCuonSach = " + info.MaCuonSach;
            bool flag = this.executeNonQuery(deleteCommand);
            return flag;
        }
    }
}
